Path deps outside workspace are not members
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 22 Dec 2016 17:56:40 +0000 (20:56 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 14 Jan 2017 20:52:19 +0000 (23:52 +0300)
closes #3192

src/cargo/core/workspace.rs
tests/workspaces.rs

index 13898323010bb11632b27b57f4b1d37daabf606a..fdd14ee23e382febf1777162cfd7604e81dd8fe4 100644 (file)
@@ -293,21 +293,28 @@ impl<'cfg> Workspace<'cfg> {
         };
 
         if let Some(list) = members {
-            let root = root_manifest.parent().unwrap();
             for path in list {
+                let root = root_manifest.parent().unwrap();
                 let manifest_path = root.join(path).join("Cargo.toml");
-                self.find_path_deps(&manifest_path)?;
+                self.find_path_deps(&manifest_path, false)?;
             }
         }
 
-        self.find_path_deps(&root_manifest)
+        self.find_path_deps(&root_manifest, false)
     }
 
-    fn find_path_deps(&mut self, manifest_path: &Path) -> CargoResult<()> {
+    fn find_path_deps(&mut self, manifest_path: &Path, is_path_dep: bool) -> CargoResult<()> {
         let manifest_path = paths::normalize_path(manifest_path);
         if self.members.iter().any(|p| p == &manifest_path) {
             return Ok(())
         }
+        if is_path_dep
+            && !manifest_path.parent().unwrap().starts_with(self.root())
+            && self.find_root(&manifest_path)? != self.root_manifest {
+            // If `manifest_path` is a path dependency outside of the workspace,
+            // don't add it, or any of its dependencies, as a members.
+            return Ok(())
+        }
 
         debug!("find_members - {}", manifest_path.display());
         self.members.push(manifest_path.clone());
@@ -326,7 +333,7 @@ impl<'cfg> Workspace<'cfg> {
                .collect::<Vec<_>>()
         };
         for candidate in candidates {
-            self.find_path_deps(&candidate)?;
+            self.find_path_deps(&candidate, true)?;
         }
         Ok(())
     }
index 86775d81587a33923fea6fefb06c279159b78621..51cb366c3ed829ca828012505e04b7f4bfdb21f9 100644 (file)
@@ -1100,4 +1100,32 @@ fn relative_path_for_member_works() {
 
     assert_that(p.cargo("build").cwd(p.root().join("foo")), execs().with_status(0));
     assert_that(p.cargo("build").cwd(p.root().join("bar")), execs().with_status(0));
+}
+
+#[test]
+fn path_dep_outside_workspace_is_not_member() {
+    let p = project("foo")
+        .file("ws/Cargo.toml", r#"
+            [project]
+            name = "ws"
+            version = "0.1.0"
+            authors = []
+
+            [dependencies]
+            foo = { path = "../foo" }
+
+            [workspace]
+        "#)
+        .file("ws/src/lib.rs", r"extern crate foo;")
+        .file("foo/Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.1.0"
+            authors = []
+        "#)
+        .file("foo/src/lib.rs", "");
+    p.build();
+
+    assert_that(p.cargo("build").cwd(p.root().join("ws")),
+                execs().with_status(0));
 }
\ No newline at end of file